#!/bin/sh

indicator_module="@kmodule_name@.ko"
indicator_name="result"

. ../test_common.sh

result_file="need_simulate"
filecontent="some_string"

init_test

echo "$indicator_name" > "${point_dir}/current_indicator"

if test $? -ne 0; then
	printf "Cannot set indicator for the point.\n"
	finalize_test
	exit 1
fi

if  ! simulate; then
	printf "Simulate shouldn't fail with \"never\" scenario.\n"
	finalize_test
	exit 1
fi

if  ! test -e "${point_dir}/${result_file}"; then
	printf "File '%s' is not created.\n" "${point_dir}/${result_file}"
	finalize_test
	exit 1
fi

if  ! test -r "${point_dir}/${result_file}"; then
	printf "File '%s' cannot be read.\n" "${point_dir}/${result_file}"
	finalize_test
	exit 1
fi

if  test "`cat "${point_dir}/${result_file}"`" != "0"; then
	printf "The contents of the file are '%s' but should be '%s'.\n" `cat "${point_dir}/${result_file}"` "0"
	finalize_test
	exit 1
fi

if  ! test -w "${point_dir}/${result_file}"; then
	printf "File '%s' cannot be written.\n" "${point_dir}/${result_file}"
	finalize_test
	exit 1
fi

echo 1 > "${point_dir}/${result_file}"

if test $? -ne 0; then
	printf "Cannot write '1' to file.\n"
	finalize_test
	exit 1
fi

if  test "`cat "${point_dir}/${result_file}"`" == "0"; then
	printf "The contents of the file have not changed.\n"
	finalize_test
	exit 1
fi

if  simulate; then
	printf "Simulate should fail with \"always\" scenario.\n"
	finalize_test
	exit 1
fi


finalize_test
